/**
 * 设置广告亮度
 */

import {Form, message, Modal, Slider } from "antd";
import { FC } from "react";
import { useWindowFontSize } from "../../../../../assets/fun/Antd/configprovider";
import { getGbSystemSetLuminance } from "../../api";

const SetUpAd: FC<{
  open: boolean; // 弹窗是否展示
  clickId?: React.Key; // 点击ID
  handleCallBack: () => void;
}> = ({ open, clickId, handleCallBack }) => {
  const [form] = Form.useForm();
  const { validateFields, resetFields } = form;
  const handleOk = async () => {
    const values = await validateFields();
    const { code, msg } = (await getGbSystemSetLuminance({
      ...values,
      id: clickId,
    })) as {
      code: number;
      msg: string;
    };
    if (code === 20000) {
      message.success("设置成功");
      resetFields();
      handleCallBack();
    } else {
      message.error(msg);
    }
  };
  const handleCancel = async () => {
    handleCallBack();
  };
  return (
    <Modal
      width={useWindowFontSize(520)}
      title={"调节亮度"}
      
      open={open}
      onOk={handleOk}
      onCancel={handleCancel}
      getContainer={false}
    >
      <Form
        form={form}
        labelCol={{ span: 8 }}
        wrapperCol={{ span: 16 }}
        labelAlign="left"
        initialValues={{
          luminance: 1,
        }}
      >
        <Form.Item
          label="亮度"
          name="luminance"
          rules={[{ required: true, message: "请选择亮度！" }]}
        >
         <Slider min={1} max={15}  />
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default SetUpAd;
